/**
 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "arduino.h"

static arduino_client *g_arduino_client_head;

void arduino_add(arduino_client *client, setup_t setup, loop_t loop)
{
    client->next = g_arduino_client_head;
    client->setup = setup;
    client->loop = loop;
    g_arduino_client_head = client;
}

void arduino_setup(void)
{
    arduino_client *head = g_arduino_client_head;

    while (head) {
        if (head->setup) {
            head->setup();
        }
        head = head->next;
    }
}

void arduino_loop(void)
{
    arduino_client *head = g_arduino_client_head;

    while (head) {
        if (head->loop) {
            head->loop();
        }
        head = head->next;
    }
}
